using System;
using Script.Utilities;
using UnityEngine;
using UnityEngine.SceneManagement;
using EventHandler = Utilities.EventHandler;

namespace Script
{
    public class GameEnd : MonoBehaviour
    {
        private void OnEnable()
        {
            EventHandler.GameOverValue += EndGameScene;
        }

        private void OnDisable()
        {
            EventHandler.GameOverValue -= EndGameScene;

        }

        private void EndGameScene(GameValues obj)
        {
            if (obj.numberOfPeople == 0)
            {
                PlayerSetting.deadReson = "人们抛弃了你，转而相信了其他神明，或许是（马桶神|行李箱神|喇叭神|皮鞋神|猫猫神……|）吧";
            }
            if (obj.technology == 0)
            {
                PlayerSetting.deadReson = "你的信徒没有任何防御手段，也没有自理能力，被外来侵略者袭击而亡，再也没人相信你了。(科技值归零)";
            }
            if (obj.happiness == 0)
            {
                PlayerSetting.deadReson = "人们对你不满，想把你从外面敲碎，但是发现敲不碎，就把你沉到海底了。（咕噜咕噜咕噜）";
            }
            PlayerSetting.score = (int)obj.height;
            Debug.Log(PlayerSetting.deadReson);
            SceneManager.LoadSceneAsync("EndScene");
        }
    }
}